Repository navigation
Return nil from Date#<=> for a NaN - #199
Open
thomasklemm wants to merge 1 commit into
Open
thomasklemm wants to merge 1 commit into
thomasklemm wants to merge 1 commit into
Conversation
Date#<=> passed the result of ajd <=> other to rb_cmpint, which turns the nil that Rational#<=> returns for a NaN into an ArgumentError, so Date <=> Float::NAN raised and Date == Float::NAN raised with it. Return the result unchanged, as Integer#<=> and Rational#<=> do.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for maintaining date.
Date#<=>raisesArgumentError("comparison of Rational with NaN failed") when the other value isFloat::NANorBigDecimal("NaN"), andDate#==raises with it, while1 <=> Float::NAN,Rational(1) <=> Float::NANandTime.now <=> Float::NANreturnnil.cmp_genpasses the result ofajd <=> othertorb_cmpint, which turns thenilfromRational#<=>into that exception.This returns the result unchanged.
Date <=> NaNis nownilandDate == NaNisfalse, whileDate < NaNstill raisesArgumentError, as for Integer. The new test covers both NaNs, so I added bigdecimal to the development group. The suite passes on Ruby 4.0.9 and master.Found while comparing Active Model's
changed?on Rails 8.1 and main with random attribute values, where a NaN assigned to a date attribute raised (record, part of my research project Lowrail).